<template>
	<view class="enter">
		<view class="univer-tabs">
			<u-tabs-swiper ref="uTabs" :list="tabList" :current="current" @change="tabsChange" :is-scroll="false"
				active-color="#20b86f" swiperWidth="750"></u-tabs-swiper>
		</view>
		<scroll-view :scroll-y="true" @scrolltolower="scroolBtm" style="height: calc(100vh - 80rpx);">
			<view class="search-table">
				<u-table v-if="tableList.length>0">
					<u-tr>
						<u-th>专业名称</u-th>
						<u-th>录取最高同位分</u-th>
						<u-th>录取平均同位分</u-th>
						<u-th>录取最低同位分</u-th>
					</u-tr>
					<u-tr v-for="(item,i) in tableList" :key="i">
						<u-td><view class="search-href" @click="goto('../pages/enterPercent', item)">{{item.title}}</view></u-td>
						<u-td>{{item.grade_step_enroll_max}}</u-td>
						<u-td>{{item.grade_step_enroll_avg}}</u-td>
						<u-td>{{item.grade_step_enroll_min}}</u-td>
					</u-tr>
				</u-table>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [],
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				year: '',
				school_code: '',
				school_batch_type: '',
				page: 1,
				tableList: [],
				finish: false
			}
		},
		onLoad(options) {
			this.school_code = options.school_code;
			this.school_batch_type = options.school_batch_type;
			this.getList('first');
		},
		methods: {
			goto(name, item) {
				uni.navigateTo({
					url: name+"?school_code="+item.school_code+"&major_type="+item.major_type+"&major_id="+item.id
				});
			},
			// tabs通知swiper切换
			tabsChange(index) {
				if(this.current !== index){
					this.current = index;
					this.year = this.tabList[index].name;
					this.tableList = [];
					this.page = 1;
					this.getList();
					this.page = 2;
					this.getList();
				}
			},
			getList(type) {
				this.http({
					url: `api/v1/majors/get_list`,
					method: 'GET',
					data: {
						page: this.page,
						year: this.year,
						school_code: this.school_code,
						school_batch_type: this.school_batch_type,
						analyze_type: 1
					},
					success: res => {
						if(this.tabList.length<=0) {
							for (let s of res.result.year) {
								this.tabList.push({name: s})
							}
						}
						if (res.errcode == 0) {
							if(res.result.list.length>0){
								if(type == 'first') {
									this.page = 2;
									this.getList();
								}
								for (let s of res.result.list) {
									this.tableList.push(s);
								}
							}else {
								this.finish = true;
							}
						}
					},
				})
			},
			scroolBtm() {
				if(!this.finish) {
					this.page++;
					this.getList();
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.search-table {
		.search-href {
			color: #3a81ff;
		}
	}
	.no-data {
		text-align: center;
		margin-top: 200rpx;
		color: #999999;
	}
</style>
<style>
	page {
		background-color: #F5F5F5;
	}
</style>
